<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/23 0023
 * Time: 下午 15:58
 */

namespace Home\Model;
use Think\Model;

class GroupMemberModel extends Model{
    //获取群组信息
    public function getGroupInfo(){
        return $this->field('id,name')->select();
    }

    //检测选中的群组在当前的时间段是否被占用
    public function jcQzInfo($qzid,$time){
        $time = explode('--',$time);
        $date = $time[0];
        array_shift($time);
        //dump($time);
        foreach($time as $k=>$v){
            $v = strtotime($v);
            $time[$k] = $v ;
        }

        $where = "date='{$date}' and type not in (2,5)";
        $data = D('meeting_notes')->field('ch_qz,date,use_time')->where($where)->select();
        //dump($data);
        $arr = [];
        $qzid = explode(',',$qzid);
        foreach($qzid as $k=>$v){
            foreach($data as $k1=>$v1){
                if(strpos($v1['ch_qz'],$v) !== false){
                    $use_time = explode('--',$v1['use_time']);
                    foreach($use_time as $k2=>$v2){
                        $use_time[$k2] = strtotime($v2);
                    }
                    $arr[$v][] = $use_time;
                }
            }
        }

        $row = [];
        foreach($arr as $k=>$v){
            foreach($v as $k1=>$v1){
                if( !($time[1]<=$v1[0]) && !($time[0]>=$v1[1]) ){
                    $row[] = $k;
                    break;
                }
            }
        }
        //dump($row);
        if($row){
            $groupname = [];
            foreach($row as $k=>$v){
                $groupname[] = $this->field('name')->find($v);
            }
            $groupname = implode(',',array_column($groupname,'name'));
            return $groupname;
        }else{
            return false ;
        }

    }

}
